<template>
    <div class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
      <el-form-item label="学年" prop="semester">
          <el-input
            v-model="queryParams.year"
            placeholder="请输入学年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="学期" prop="semester">
          <el-input
            v-model="queryParams.semester"
            placeholder="请输入学期"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成绩" prop="scoreNum">
            <el-input-number v-model="queryParams.scoreBeginNum" controls-position="right"  :min="1" :max="100" placeholder="请输入开始成绩" clearable></el-input-number>
            至
            <el-input-number v-model="queryParams.scoreEndNum" controls-position="right"  :min="1" :max="100" placeholder="请输入结束成绩" clearable></el-input-number>
        </el-form-item>
        <el-form-item label="课程名称" prop="courseName">
          <el-input
            v-model="queryParams.courseName"
            placeholder="请输入课程名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="教师名称" prop="teacherName">
          <el-input
            v-model="queryParams.teacherName"
            placeholder="请输入教师名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        
        <!-- <el-form-item label="分数" prop="scoreNum">
          <el-input
            v-model="queryParams.scoreNum"
            placeholder="请输入分数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['edu:score:export']"
            >导出</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
  
      <el-table
        v-loading="loading"
        :data="scoreList"
      >
        <el-table-column label="学生名称" align="center" prop="studentName" />
        <el-table-column label="课程名称" align="center" prop="courseName" />
        <el-table-column label="教师名称" align="center" prop="teacherName" />
        <el-table-column label="学年" align="center" prop="year" />
        <el-table-column label="学期" align="center" prop="semester" />
        <el-table-column label="分数" align="center" prop="scoreNum" />
        <!-- <el-table-column
          label="考试时间"
          align="center"
          prop="examTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.examTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column> -->
      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </template>
  
  <script>
  import {
    listScore,
    getScore,
    delScore,
    addScore,
    updateScore,
    listStudentScore
  } from "@/api/edu/score";
  import { listCourse } from "@/api/edu/course";
  import { listStudent,getStudent, delStudent, addStudent, updateStudent } from "@/api/edu/student";
  import { listClass } from "@/api/edu/class";
  import {listTeacher, deptTreeSelect } from "@/api/system/user";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
    name: "Score",
    components: { Treeselect },
    data() {
      return {
        // 遮罩层
        loading: true,
        teacherList:null,
        // 选中数组
        ids: [],
        time: [],
        selectedTeacher:null,
        courseNameList:null,
        classNameList:null,
        currentTime: new Date().getFullYear(),
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        studentList:[],
        studentNames:null,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        StudentLoading:false,
        // 成绩表格数据
        scoreList: [],
        courseNames:"",
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          studentName: null,
          courseName: null,
          teacherName: null,
          year: null,
          semester: null,
          scoreBeginNum: 0,
          scoreEndNum: 100,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
      };
    },
    created() {
      this.getList();
      this.getCurrentYear ()
    },
    methods: {
      //获取当前的年份和学期
    getCurrentYear () {
      this.getConfigKey("edu.current.year.semester").then(response => {
        console.log(response)
        let yearSemester = response.msg
        let yearSemesterArr = yearSemester.split("-")
        this.queryParams.year = Number(yearSemesterArr[0]);
        this.queryParams.semester = Number(yearSemesterArr[1]);
      });
    },
      /** 查询成绩列表 */
      getList() {
        this.loading = true;
        listStudentScore(this.queryParams).then((response) => {
          this.scoreList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 表单重置
      reset() {
        this.form = {
          scoreId: null,
          studentId: null,
          studentName: null,
          courseId: null,
          courseName: null,
          teacherId: null,
          teacherName: null,
          deptId: null,
          deptName: null,
          year: null,
          semester: null,
          classId: null,
          className: null,
          scoreNum: null,
          examTime: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          collegeId: null,
          collegeName: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.selectedTeacher  =  "",
        this.courseNameList = "",
        this.classNameList = ""
        this.studentNames = ""
        this.handleQuery();
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "edu/score/export/list",
          {
            ...this.queryParams,
          },
          `score_${new Date().getTime()}.xlsx`
        );
      },
  
    },
  };
  </script>